
//
//  ZTForgetPswController.m
//  ZTTaxSecond
//
//  Created by Zhengtong on 15/11/26.
//  Copyright © 2015年 Zhengtong. All rights reserved.
//

#import "ZTForgetPswController.h"

#import "NSObject+ToolObject.h"
#import "ZTRootTool.h"

@interface ZTForgetPswController ()
@property (weak, nonatomic) IBOutlet UIButton *finishBtn;
- (IBAction)finishBtnClick:(id)sender;
@property (weak, nonatomic) IBOutlet UITextField *taxerTextField;
@property (weak, nonatomic) IBOutlet UITextField *emailTextField;

@end

@implementation ZTForgetPswController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpNavgationBar];
}
#pragma mark - 设置导航条
- (void)setUpNavgationBar
{
    self.title = @"找回密码";
     self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    self.automaticallyAdjustsScrollViewInsets = YES;
    
    self.navigationController.navigationBar.hidden = NO;
    //导航条背景图片
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"上栏"] forBarMetrics:UIBarMetricsDefault];
    //导航标题颜色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    
    UIBarButtonItem *backBtnItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithOriginalName:@"返回按钮.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBtnClick)];
    
    self.navigationItem.leftBarButtonItem = backBtnItem;
}
- (void)leftBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (IBAction)finishBtnClick:(id)sender {
    
    [self.taxerTextField resignFirstResponder];
     [self.emailTextField resignFirstResponder];
    
    if (![self judgmentIsEmpty:self.taxerTextField.text]) {
        [self showHUD:@"用户名不能为空"];
    }else if (![self judgmentIsEmpty:self.emailTextField.text]){
        [self showHUD:@"邮箱账号不能为空"];
    }else if (![ZTRootTool isValidateEmail:self.emailTextField.text]){
        [self showHUD:@"邮箱格式不正确"];
    }else{
        NSDictionary *dict = @{@"userId":self.taxerTextField.text,
                              @"selectEmail" :self.emailTextField.text};
        
        [RequestTool requestForgetUserId:self.taxerTextField.text withParams:dict WithBlock:^(id result, NSString *error) {
            if (error == nil) {
                [self showHUD:result];
                [self performSelector:@selector(forget) withObject:self afterDelay:1];
            }else{
                [self showHUD:error];
            }

        }];
    }
}
- (void)forget
{
    [self.navigationController popViewControllerAnimated:YES];
}


@end
